<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Javascript的class继承</h1>
<hr>
<script>

    //1.class继承
    /*
    class Animal{
        constructor(weight,height){
            this.weight = weight;
            this.height = height;
        }
    }

    class Person extends Animal{
        constructor(name,gender,weight,height){
            super(weight,height);
            this.name = name;
            this.gender = gender;
        }

        thinking(){
            console.log(this.name+" is thinking now!");
        }
    }

    let p = new Person('张三','男',65,170);
    console.log(p);
    p.thinking();
    */


    //2.也允许子类重写父类继承过来的方法

    class Animal{
        constructor(weight,height){
            this.weight = weight;
            this.height = height;
        }
        sleep(){
            console.log('animal is sleeping...');
        }
    }

    class Person extends Animal{
        constructor(name,gender,weight,height){
            super(weight,height);
            this.name = name;
            this.gender = gender;
        }
        sleep(){
            console.log(this.name+"正躺在床上 sleep....");
        }

        thinking(){
            console.log(this.name+" is thinking now!");
        }
    }
    let p = new Person('张三','男',65,170);
    console.log(p);
    p.thinking();
    p.sleep();
</script>
</body>
</html>